package cn.legend.travel.admin.comment.controller;

import cn.legend.travel.admin.comment.service.ICommentService;
import cn.legend.travel.common.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@Api("评论审核模块")
@RestController
@RequiredArgsConstructor
@RequestMapping("comments")
public class CommentController {
    private final ICommentService service;

    @GetMapping("{type}/list")
    @ApiOperation("评论查看功能")
    @PreAuthorize("hasAuthority('/comments/check')")
    public JsonResult getCommentList(@PathVariable String type, Integer pageNum) {
        return JsonResult.ok(service.getCommentList(type, pageNum == null ? 1 : pageNum));
    }

    @PostMapping("{type}/delete")
    @ApiOperation("删除评论功能")
    @PreAuthorize("hasAuthority('/comments/check')")
    public JsonResult deleteById(@PathVariable String type, @RequestParam Long id) {
        service.deleteById(type, id);
        return JsonResult.ok();
    }

    @PostMapping("{type}/pass")
    @ApiOperation("审核评论通过功能")
    @PreAuthorize("hasAuthority('/comments/check')")
    public JsonResult passById(@PathVariable String type, @RequestParam Long id) {
        service.passById(type, id);
        return JsonResult.ok();
    }
}
